/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.permit.controller.model.vo;

import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.siufung.core.model.AbstractVo;
import net.siufung.core.model.enums.DeletedEnum;
import net.siufung.market.base.permit.enums.AccessStates;
import net.siufung.market.base.permit.enums.BusinessTypes;

import java.time.LocalDateTime;

/**
 * @author 陈建峰
 * @since 2022-07-05 22:19:50
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="MenuVo", description="系统菜单表")
public class MenuVo extends AbstractVo {

    private static final long serialVersionUID = 8825475161493137796L;

    /**
     * 主键id
     */
    @ApiModelProperty(value = "主键id")
    private Integer id;

    /**
     * 菜单名称
     */
    @ApiModelProperty(value = "菜单名称")
    private String menuName;

    /**
     * 菜单编码
     */
    @ApiModelProperty(value = "菜单编码")
    private String menuCode;

    /**
     * 菜单类型
     */
    @ApiModelProperty(value = "菜单状态")
    private Boolean externalState;

    /**
     * 外部链接
     */
    @ApiModelProperty(value = "外部链接")
    private String externalUrl;

    /**
     * 菜单父级id
     */
    @ApiModelProperty(value = "菜单父级id")
    private Integer parentId;

    /**
     * 菜单父级名称
     */
    @ApiModelProperty(value = "菜单父级名称")
    private String parentName;

    /**
     * 菜单路径
     */
    @ApiModelProperty(value = "菜单路径")
    private String router;

    /**
     * 菜单全路径
     */
    @ApiModelProperty(value = "菜单全路径")
    private String fullPath;

    /**
     * 页面缓存
     */
    @ApiModelProperty(value = "页面缓存")
    private Boolean keepAlive;

    /**
     * 菜单图标
     */
    @ApiModelProperty(value = "菜单图标")
    private String icon;

    /**
     * 菜单级别
     */
    @ApiModelProperty(value = "菜单级别")
    private Integer level;

    /**
     * 访问类型 0不可访问 1可访问
     */
    @ApiModelProperty(value = "访问类型 0不可访问 1可访问")
    private Boolean accessState;

    /**
     * 菜单业务类型
     */
    @ApiModelProperty(value = "菜单业务类型")
    private String businessType;

    /**
     * 系统应用id
     */
    @ApiModelProperty(value = "系统应用id")
    private Integer appId;

    /**
     * 菜单排序
     */
    @ApiModelProperty(value = "菜单排序")
    private Integer sequence;

    /**
     * 权限标识
     */
    @ApiModelProperty(value = "权限标识")
    private String sign;

    /**
     * 菜单描述
     */
    @ApiModelProperty(value = "菜单描述")
    private String description;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String createdBy;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime createdAt;

    /**
     * 更新人
     */
    @ApiModelProperty(value = "更新人")
    private String updatedBy;

    /**
     * 更新时间
     */
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    private LocalDateTime updatedAt;

    /**
     * 数据标识
     */
    @ApiModelProperty(value = "数据标识")
    private Boolean deleted;

    @Override
    public String getDeletedDesc() {
        return DeletedEnum.getDesc(deleted);
    }

    public String getAccessStateDesc(){
        return AccessStates.getDesc(accessState);
    }

    public String getBusinessTypeDesc(){
        return BusinessTypes.getDesc(businessType);
    }

    @Override
    public boolean getAllowRemove() {
        return parentId != 0 && DeletedEnum.NOT.equals(DeletedEnum.get(deleted));
    }

    @Override
    public boolean getAllowUpdate() {
        return parentId != 0 && DeletedEnum.NOT.equals(DeletedEnum.get(deleted));
    }

    @Override
    public boolean getAllowStatus() {
        return parentId != 0;
    }
}